package com.sophialex.health.record.ui.query;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.part.ViewPart;

import com.sophialex.health.record.Messages;
import com.sophialex.health.record.common.GeographyTreeCombo;
import com.sophialex.health.record.common.GeographyTreeInit;
import com.sophialex.health.record.common.showKtable.ShowKTable;
import com.sophialex.health.record.common.util.ImageUtil;
import com.sophialex.health.record.common.utils.CommonUtils;
import com.sophialex.health.record.common.validate.TextVerifyListener;
import com.sophialex.health.record.lktable.join.HrPersonQueryJoinOut;
import com.sophialex.health.system.frame.resource.RcpResourceManager;

public abstract class HrPersonQueryUI extends ViewPart{
	protected Button printYPZF;
	public static final String ID = "com.sophialex.health.record.ui.query.HrPersonQueryUI"; 
	private ToolBar toolBar;
	private Composite topComposite;
	protected SashForm tableComposite;
	protected Text nPageText;
	protected Text pdTimeText;
	protected Text zwDateText;
	protected Text nCountText;
	protected ToolItem queryItem, openItem,exitItem,tzItem;
	protected ShowKTable showTable;
	protected Button pdrkButton, printPDButton, printKCButton, showCEButton;
	protected CLabel sumCountLabel, curCountLabel, sumPageLabel, curPageLabel;
	protected Button firstButton, preButton, nextButton, lastButton;
	protected Text text_name,txt_idno,txt_sage,txt_eage,txt_dabh;
	private Label label_1,label_birthday,label_z,label_jwh,label_zrys,label_jdr,label_showSize;
	protected Combo combo_sex,combo_zrys,combo_jdr;
	private Label label_2;
	protected GeographyTreeCombo combo_jwh; // 村委会/居委会
	protected GeographyTreeInit treeObj = new GeographyTreeInit();

	public HrPersonQueryUI() {
	}

	/**
	 * Create contents of the view part.
	 * 
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);
		container.setLayout(new FormLayout());
		{
			toolBar = new ToolBar(container, SWT.FLAT);
			toolBar.setBackgroundImage(ImageUtil.toolbar);
			{
				FormData formData = new FormData();
				formData.height = 50;
				formData.right = new FormAttachment(100);
				formData.top = new FormAttachment(0);
				formData.left = new FormAttachment(0);
				toolBar.setLayoutData(formData);
			}
			{
				queryItem = new ToolItem(toolBar, SWT.NONE);
				queryItem.setImage(ImageUtil.query);
				queryItem.setText(Messages.getString("HrPersonQueryUI.0")); //$NON-NLS-1$
				queryItem.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						doQuery();
					}
				});
			}
			{
				openItem = new ToolItem(toolBar, SWT.NONE);
				openItem.setImage(ImageUtil.locate);
				openItem.setText(Messages.getString("HrPersonQueryUI.2")); //$NON-NLS-1$
				openItem.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						doOpenRecord();
					}
				});
			}
			{
				tzItem = new ToolItem(toolBar, SWT.NONE);
				tzItem.setImage(ImageUtil.tz);
				tzItem.setText(Messages.getString("HrPersonQueryUI.12")); //$NON-NLS-1$
				tzItem.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						doAccount();
					}
				});
			}
			{
				ToolItem toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
			}
			{
				exitItem = new ToolItem(toolBar, SWT.NONE);
				exitItem.setImage(ImageUtil.exit);
				exitItem.setText(Messages.getString("HrPersonQueryUI.1")); //$NON-NLS-1$
				exitItem.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						doExit();
					}
				});
			}
		}
		{
			topComposite = new Composite(container, SWT.BORDER);
			topComposite.setLayout(new FormLayout());
			{
				FormData formData = new FormData();
				formData.height = 90;
				formData.right = new FormAttachment(toolBar, 0, SWT.RIGHT);
				formData.width = 276;
				formData.left = new FormAttachment(toolBar, 0, SWT.LEFT);
				formData.top = new FormAttachment(toolBar, 0);
				topComposite.setLayoutData(formData);
			}
			
			topComposite.setBackground(RcpResourceManager
					.getColor(SWT.COLOR_WHITE));
			topComposite.setBackgroundMode(SWT.INHERIT_DEFAULT);

		}
		{
			tableComposite = new SashForm(container, SWT.NONE);
			tableComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
			{
				FormData formData = new FormData();
				formData.right = new FormAttachment(toolBar, 0, SWT.RIGHT);
				formData.left = new FormAttachment(toolBar, 0, SWT.LEFT);
				formData.top = new FormAttachment(topComposite, 0);
				
				Label label = new Label(topComposite, SWT.NONE);
				FormData fd_label = new FormData();
				fd_label.top = new FormAttachment(0, 15);
				fd_label.left = new FormAttachment(0, 25);
				label.setLayoutData(fd_label);
				label.setText(Messages.getString("HrPersonDiag.2"));
				
				text_name = new Text(topComposite, SWT.BORDER);
				FormData fd_text = new FormData();
				fd_text.right = new FormAttachment(label, 136, SWT.RIGHT);
				fd_text.top = new FormAttachment(0, 7);
				fd_text.bottom = new FormAttachment(label, 0, SWT.BOTTOM);
				fd_text.left = new FormAttachment(label, 6);
				text_name.setLayoutData(fd_text);
				{
					label_1 = new Label(topComposite, SWT.NONE);
					FormData fd_label_1 = new FormData();
					fd_label_1.bottom = new FormAttachment(label, 0, SWT.BOTTOM);
					fd_label_1.left = new FormAttachment(text_name, 45);
					label_1.setLayoutData(fd_label_1);
					label_1.setText(Messages.getString("HrPersonDiag.3"));
				}
				
				combo_sex = new Combo(topComposite, SWT.NONE);
				FormData fd_combo = new FormData();
				fd_combo.right = new FormAttachment(label_1, 136, SWT.RIGHT);
				fd_combo.top = new FormAttachment(0, 7);
				fd_combo.left = new FormAttachment(label_1, 6);
				fd_combo.bottom = new FormAttachment(label_1, 0, SWT.BOTTOM);
				combo_sex.setLayoutData(fd_combo);
				
				Label label_idno = new Label(topComposite, SWT.NONE);
				FormData fd_idno = new FormData();
				fd_idno.top = new FormAttachment(0, 15);
				fd_idno.left = new FormAttachment(combo_sex, 45);
				fd_idno.bottom = new FormAttachment(combo_sex, 0,SWT.BOTTOM);
				label_idno.setLayoutData(fd_idno);
				label_idno.setText(Messages.getString("HrPersonDiag.5"));
				
				
				{
					txt_idno = new Text(topComposite, SWT.BORDER);
					FormData fd_txt_idno = new FormData();
					fd_txt_idno.right = new FormAttachment(label_idno, 136, SWT.RIGHT);
					fd_txt_idno.top = new FormAttachment(0, 7);
					fd_txt_idno.bottom = new FormAttachment(label_idno, 0, SWT.BOTTOM);
					fd_txt_idno.left = new FormAttachment(label_idno, 6);
					txt_idno.setLayoutData(fd_txt_idno);
				}
				
				{
					label_jwh = new Label(topComposite, SWT.NONE);
					FormData fd_jwh = new FormData();
					fd_jwh.top = new FormAttachment(0, 15);
					fd_jwh.left = new FormAttachment(txt_idno, 45);
					fd_jwh.bottom = new FormAttachment(txt_idno, 0,SWT.BOTTOM);
					label_jwh.setLayoutData(fd_jwh);
					label_jwh.setText(Messages.getString("HrPersonQueryUI.5"));
				}
				{
					combo_jwh = new GeographyTreeCombo(topComposite, treeObj, SWT.READ_ONLY | SWT.SIMPLE);
					FormData fd_combo_jwh = new FormData();
					fd_combo_jwh.right = new FormAttachment(label_jwh, 210, SWT.RIGHT);
					fd_combo_jwh.top = new FormAttachment(0, 7);
					fd_combo_jwh.bottom = new FormAttachment(label_jwh, 0, SWT.BOTTOM);
					fd_combo_jwh.left = new FormAttachment(label_jwh, 15);
					combo_jwh.setLayoutData(fd_combo_jwh);
				}
				
				{
					label_birthday = new Label(topComposite, SWT.NONE);
					FormData fd_birthday = new FormData();
					fd_birthday.top = new FormAttachment(0, 15);
					fd_birthday.left = new FormAttachment(combo_jwh, 45);
					fd_birthday.bottom = new FormAttachment(combo_jwh, 0,SWT.BOTTOM);
					label_birthday.setLayoutData(fd_birthday);
					label_birthday.setText(Messages.getString("HrPersonQueryUI.3"));
				}
				
				{
					txt_sage = new Text(topComposite, SWT.BORDER);
					FormData fd_txt_sage = new FormData();
					fd_txt_sage.right = new FormAttachment(label_birthday, 70, SWT.RIGHT);
					fd_txt_sage.top = new FormAttachment(0, 7);
					fd_txt_sage.bottom = new FormAttachment(label_birthday, 0, SWT.BOTTOM);
					fd_txt_sage.left = new FormAttachment(label_birthday, 6);
					txt_sage.setLayoutData(fd_txt_sage);
				}
				
				{
					label_z = new Label(topComposite, SWT.NONE);
					FormData fd_z = new FormData();
					fd_z.top = new FormAttachment(0, 15);
					fd_z.left = new FormAttachment(txt_sage, 15);
					fd_z.bottom = new FormAttachment(txt_sage, 0,SWT.BOTTOM);
					label_z.setLayoutData(fd_z);
					label_z.setText(Messages.getString("HrPersonQueryUI.4"));
				}
				
				{
					txt_eage = new Text(topComposite, SWT.BORDER);
					FormData fd_txt_eage = new FormData();
					fd_txt_eage.right = new FormAttachment(label_z, 70, SWT.RIGHT);
					fd_txt_eage.top = new FormAttachment(0, 7);
					fd_txt_eage.bottom = new FormAttachment(label_z, 0, SWT.BOTTOM);
					fd_txt_eage.left = new FormAttachment(label_z, 15);
					txt_eage.setLayoutData(fd_txt_eage);
				}
				
				
				{
					label_2 = new Label(topComposite, SWT.NONE);
					FormData fd_label_2 = new FormData();
					fd_label_2.top = new FormAttachment(label,47,SWT.TOP);
					fd_label_2.right = new FormAttachment(label,0,SWT.RIGHT);
					label_2.setLayoutData(fd_label_2);
					label_2.setText(Messages.getString("HrPersonQueryUI.6"));
				}
				
				
				{
					txt_dabh = new Text(topComposite, SWT.BORDER);
					FormData fd_txt_dabh = new FormData();
					fd_txt_dabh.right = new FormAttachment(label_2, 136, SWT.RIGHT);
					fd_txt_dabh.top = new FormAttachment(label_2,-8,SWT.TOP);
					fd_txt_dabh.bottom = new FormAttachment(label_2, 0, SWT.BOTTOM);
					fd_txt_dabh.left = new FormAttachment(label_2, 6);
					txt_dabh.setLayoutData(fd_txt_dabh);
				}
				
				{
					label_zrys = new Label(topComposite, SWT.NONE);
					FormData fd_label_zrys = new FormData();
					fd_label_zrys.bottom = new FormAttachment(label_2, 0, SWT.BOTTOM);
					fd_label_zrys.right = new FormAttachment(label_1, 0,SWT.RIGHT);
					label_zrys.setLayoutData(fd_label_zrys);
					label_zrys.setText(Messages.getString("HrPersonQueryUI.7"));
				}
				
				{
					combo_zrys = new Combo(topComposite, SWT.NONE);
					FormData fd_txt_zrys = new FormData();
					fd_txt_zrys.right = new FormAttachment(label_zrys, 136, SWT.RIGHT);
					fd_txt_zrys.top = new FormAttachment(txt_dabh,0,SWT.TOP);
					fd_txt_zrys.bottom = new FormAttachment(label_zrys, 0, SWT.BOTTOM);
					fd_txt_zrys.left = new FormAttachment(label_zrys, 6);
					combo_zrys.setLayoutData(fd_txt_zrys);
				}
				
				{
					label_jdr = new Label(topComposite, SWT.NONE);
					FormData fd_label_jdr = new FormData();
					fd_label_jdr.bottom = new FormAttachment(combo_zrys, 0, SWT.BOTTOM);
					fd_label_jdr.right = new FormAttachment(label_idno,0,SWT.RIGHT);
					label_jdr.setLayoutData(fd_label_jdr);
					label_jdr.setText(Messages.getString("HrPersonQueryUI.8"));
				}
				
				{
					combo_jdr = new Combo(topComposite, SWT.NONE);
					FormData fd_txt_jdr = new FormData();
					fd_txt_jdr.right = new FormAttachment(label_jdr, 136, SWT.RIGHT);
					fd_txt_jdr.top = new FormAttachment(txt_dabh,0,SWT.TOP);
					fd_txt_jdr.bottom = new FormAttachment(label_jdr, 0, SWT.BOTTOM);
					fd_txt_jdr.left = new FormAttachment(label_jdr, 6);
					combo_jdr.setLayoutData(fd_txt_jdr);
				}
				
				{
					label_showSize = new Label(topComposite, SWT.NONE);
					FormData fd_label_showSize = new FormData();
					fd_label_showSize.bottom = new FormAttachment(combo_jdr, 0, SWT.BOTTOM);
					fd_label_showSize.right = new FormAttachment(label_birthday,0,SWT.RIGHT);
					label_showSize.setLayoutData(fd_label_showSize);
					label_showSize.setText(Messages.getString("Common.10"));
				}
				
				{
					nCountText = new Text(topComposite, SWT.BORDER);
					FormData fd_nCountText = new FormData();
					fd_nCountText.right = new FormAttachment(label_showSize, 70, SWT.RIGHT);
					fd_nCountText.top = new FormAttachment(txt_dabh,0,SWT.TOP);
					fd_nCountText.bottom = new FormAttachment(label_showSize, 0, SWT.BOTTOM);
					fd_nCountText.left = new FormAttachment(txt_sage,0,SWT.LEFT);
					nCountText.setLayoutData(fd_nCountText);
					nCountText.addVerifyListener(new TextVerifyListener(1));
				}
				
				
				
				
				formData.bottom = new FormAttachment(100, -40);
				tableComposite.setLayoutData(formData);
			}

	

			{
				showTable = new ShowKTable(tableComposite,
						"com.sophialex.health.record.ui.query.HrPersonQueryUI" //$NON-NLS-1$
								+ "showTable", true, SWT.BORDER | SWT.H_SCROLL //$NON-NLS-1$
								| SWT.V_SCROLL|SWT.FULL_SELECTION );   
				showTable.setColorColumn(new int[] { 10, 11 },
						RcpResourceManager.getColor(SWT.COLOR_BLUE));
				showTable.setTitlesAndProperties(getColumnTitles(),
						getColumnProperties());
				showTable.setColumnAligns(getColumnAligns());
				showTable.setColumnWidths(getColumnWidths());
				showTable.setJoinOut(new HrPersonQueryJoinOut());
				showTable.setBackground(RcpResourceManager
						.getColor(SWT.COLOR_LIST_BACKGROUND));
			}
//			tableComposite.setWeights(new int[] { 20, 80 });
//			composite.setVisible(false);
			tableComposite.setMaximizedControl(showTable);
		}
		{
			Composite buttomComposite = new Composite(container, SWT.BORDER);
			{
				FormData formData = new FormData();
				formData.top = new FormAttachment(tableComposite, 0);
				formData.bottom = new FormAttachment(100);
				formData.right = new FormAttachment(toolBar, 0, SWT.RIGHT);
				formData.left = new FormAttachment(toolBar, 0, SWT.LEFT);
				buttomComposite.setLayoutData(formData);
			}
			buttomComposite.setBackground(RcpResourceManager
					.getColor(SWT.COLOR_WHITE));
			buttomComposite.setBackgroundMode(SWT.INHERIT_DEFAULT);
			{
				CLabel label = new CLabel(buttomComposite, SWT.NONE);
				label.setBounds(8, 9, 60, 18);
				label.setText(Messages.getString("Common.0")); 
			}
			{
				sumCountLabel = new CLabel(buttomComposite, SWT.NONE);
				sumCountLabel.setText(""); //$NON-NLS-1$
				sumCountLabel.setBounds(74, 9, 60, 18);
			}
			{
				CLabel label = new CLabel(buttomComposite, SWT.NONE);
				label.setBounds(140, 9, 90, 18);
				label.setText(Messages.getString("Common.1")); //$NON-NLS-1$
			}
			{
				curCountLabel = new CLabel(buttomComposite, SWT.NONE);
				curCountLabel.setText(""); //$NON-NLS-1$
				curCountLabel.setBounds(236, 9, 52, 18);
			}
			{
				CLabel label = new CLabel(buttomComposite, SWT.NONE);
				label.setBounds(294, 9, 52, 18);
				label.setText(Messages.getString("Common.2")); //$NON-NLS-1$
			}
			{
				sumPageLabel = new CLabel(buttomComposite, SWT.NONE);
				sumPageLabel.setText(""); //$NON-NLS-1$
				sumPageLabel.setBounds(352, 9, 60, 18);
			}
			{
				CLabel label = new CLabel(buttomComposite, SWT.NONE);
				label.setBounds(418, 9, 52, 18);
				label.setText(Messages.getString("Common.3")); //$NON-NLS-1$
			}
			{
				curPageLabel = new CLabel(buttomComposite, SWT.NONE);
				curPageLabel.setText(""); //$NON-NLS-1$
				curPageLabel.setBounds(476, 9, 52, 18);
			}
			{
				firstButton = new Button(buttomComposite, SWT.NONE);
				firstButton.setBounds(534, 6, 52, 22);
				firstButton.setText(Messages.getString("Common.4")); //$NON-NLS-1$
			}
			{
				preButton = new Button(buttomComposite, SWT.NONE);
				preButton.setBounds(592, 6, 60, 22);
				preButton.setText(Messages.getString("Common.5")); //$NON-NLS-1$
			}
			{
				nextButton = new Button(buttomComposite, SWT.NONE);
				nextButton.setBounds(658, 6, 60, 22);
				nextButton.setText(Messages.getString("Common.6")); //$NON-NLS-1$
			}
			{
				lastButton = new Button(buttomComposite, SWT.NONE);
				lastButton.setBounds(724, 6, 60, 22);
				lastButton.setText(Messages.getString("Common.7")); //$NON-NLS-1$
			}
			{
				CLabel label = new CLabel(buttomComposite, SWT.NONE);
				label.setBounds(789, 8, 18, 18);
				label.setText(Messages.getString("Common.8")); //$NON-NLS-1$
			}
			{
				nPageText = new Text(buttomComposite, SWT.BORDER);
				nPageText.setBounds(813, 8, 40, 18);
				nPageText.addVerifyListener(new TextVerifyListener(1));
			}
			{
				CLabel label = new CLabel(buttomComposite, SWT.NONE);
				label.setBounds(859, 8, 18, 18);
				label.setText(Messages.getString("Common.9")); //$NON-NLS-1$
			}
		}

		init();
		addListener();
		createActions();
		initializeToolBar();
		initializeMenu();
		initCombo();
		
		this.setPartName(Messages.getString("HrPersonQueryUI.Title")); 
	}
    
	protected void initCombo(){
		CommonUtils.initCombo(combo_sex, "SEX");
		CommonUtils.initUserCombo(combo_jdr, null,true);
		CommonUtils.initUserCombo(combo_zrys, null,true);
	}

	/**
	 * 子类实现来设置要显示的列Alignment,如果不设置，取ShowKTable中的默认值
	 * 
	 * @return int[]
	 */
	protected int[] getColumnAligns() {
		return new int[] { ShowKTable.C, ShowKTable.C, ShowKTable.C,
				ShowKTable.C, ShowKTable.C, ShowKTable.C,ShowKTable.C, ShowKTable.C, ShowKTable.C};
	}

	/**
	 * 子类实现来设置要显示的列宽,如果不设置，取ShowKTable中的默认值
	 * 
	 * @return int[]
	 */
	protected int[] getColumnWidths() {
		return new int[] {120,100,120,150,150,80,80,200,250};
	}
	/**
	 * 子类实现来设置表头
	 * 
	 * @return String[]
	 */
	private String[] getColumnTitles() {
		return new String[] { Messages.getString("HrPersonAssist.0"), Messages.getString("HrPersonAssist.1"), Messages.getString("HrPersonAssist.2"),
				Messages.getString("HrPersonAssist.6"),
				Messages.getString("HrPersonAssist.3"), Messages.getString("HrPersonAssist.4"),Messages.getString("HrPersonQueryUI.9"),
				Messages.getString("HrPersonQueryUI.10"), Messages.getString("HrPersonAssist.5")}; 
	}

	/**
	 * 子类实现来设置要显示的属性值
	 * 
	 * @return String[]
	 */
	private String[] getColumnProperties() {
		return new String[] { "name", "sex", "birthday","archiveSerial","idno","adminUserId","archiveUserId","hamlet","cadress"}; 
	}

	protected abstract void doOpenRecord();

	protected abstract void doQuery();

	protected abstract void doAccount();
	

	protected abstract void doExit();

	protected abstract void addListener();

	protected abstract void init();

	/**
	 * Create the actions.
	 */
	private void createActions() {
		// Create the actions
	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		IToolBarManager toolbarManager = getViewSite().getActionBars()
				.getToolBarManager();
	}

	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		IMenuManager menuManager = getViewSite().getActionBars()
				.getMenuManager();
	}

	@Override
	public void setFocus() {
		// Set the focus
	}
}
